Skip to content

fix: close WebSocket on pagehide to support bfcache#162

Open
FeironoX5 wants to merge 4 commits intomasterfrom
fix/websocket-bfcache
Open

fix: close WebSocket on pagehide to support bfcache#162
FeironoX5 wants to merge 4 commits intomasterfrom
fix/websocket-bfcache

Conversation

@FeironoX5
Copy link

Original problem

Lighthouse was giving an exception "Pages with WebSocket cannot enter back/forward cache (bfcache)" because we were not closing socket on pagehide event.

PR Description

Solution from MDN reference was implemented. When reproducing notice that vite dev also opens a socket, so, instead use npx vite build with npx serve and import changing in index.html. pageshow event is ignored, because socket connection will be restored when send method will be called.

изображение

@FeironoX5 FeironoX5 requested a review from neSpecc February 13, 2026 14:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the JavaScript Socket transport to close its WebSocket connection on pagehide, enabling the page to enter the browser back/forward cache (bfcache) and addressing Lighthouse warnings.

Changes:

  • Adds a pagehide event handler that closes the WebSocket.
  • Registers/unregisters the pagehide listener when the socket opens/closes.
  • Introduces an internal close() helper to null out the socket after closing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants